﻿/*版权声明
 * 
 * 本 WebName:IMIS_ERP 由
 * 河北大学 信管团队 开发
 * 如有任何疑问请联系开发人员
 * 
 * 项目开发者
 * 负责人：朱胜贤
 * 成员：水亚亚、孙旭峰、张文元、项玥、吕芳、吴凡、谢静、李亚慧
 *
 * 如有任何疑问请联系：河北大学信管团队
 * QQ：196396337
 * Email:zagelover@163.com
 * HomePage：http://sxgzs.com/
 *
 * CopyRight (c) 河北大学信管团队 2010~2020
 */

using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using IMIS_ERP.DBUtility;//Please add references
namespace IMIS_ERP.DAL
{
    /// <summary>数据访问类:Head_FacTake
    ///     <remarks>2010-12-30 河北大学信管团队</remarks>
    /// </summary>
    public class Head_FacTake
    {
        public Head_FacTake()
        { }
        #region  Method
        /// <summary>是否存在该记录
        ///     <remarks>2010-12-30 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="hfID">编号</param>
        /// <returns>返回是否存在</returns>
        public bool Exists(int hfID)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@hfID", SqlDbType.Int)};
            parameters[0].Value = hfID;

            int result = DbHelperSQL.RunProcedure("UP_Head_FacTake_Exists", parameters, out rowsAffected);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>增加一条数据
        ///      <remarks>2010-12-30 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="model"></param>
        /// <returns>返回是否添加成功</returns>
        public bool Add(IMIS_ERP.Model.Head_FacTake model)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@hfID", SqlDbType.Int,4),
					new SqlParameter("@hfTime", SqlDbType.DateTime),
					new SqlParameter("@hfFiID", SqlDbType.NVarChar,20),
					new SqlParameter("@hfType", SqlDbType.NChar,2),
					new SqlParameter("@hfPcID", SqlDbType.NVarChar,50),
					new SqlParameter("@hfNum", SqlDbType.SmallInt,2),
					new SqlParameter("@hfWeight", SqlDbType.Decimal,9),
					new SqlParameter("@hfPrice", SqlDbType.Decimal,9),
					new SqlParameter("@hfFee", SqlDbType.Decimal,9),
					new SqlParameter("@hfRemark", SqlDbType.NVarChar,100),
					new SqlParameter("@hfHuID", SqlDbType.NVarChar,20),
					new SqlParameter("@hfVoucher", SqlDbType.NVarChar,10),
					new SqlParameter("@hfIsPay", SqlDbType.Bit,1)};
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = model.hfTime;
            parameters[2].Value = model.hfFiID;
            parameters[3].Value = model.hfType;
            parameters[4].Value = model.hfPcID;
            parameters[5].Value = model.hfNum;
            parameters[6].Value = model.hfWeight;
            parameters[7].Value = model.hfPrice;
            parameters[8].Value = model.hfFee;
            parameters[9].Value = model.hfRemark;
            parameters[10].Value = model.hfHuID;
            parameters[11].Value = model.hfVoucher;
            parameters[12].Value = model.hfIsPay;

            return DbHelperSQL.GetIsRunOK("UP_Head_FacTake_ADD", parameters);
        }

        /// <summary>更新一条数据
        ///      <remarks>2010-12-30 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="model"></param>
        /// <returns>返回是否修改成功</returns>
        public bool Update(IMIS_ERP.Model.Head_FacTake model)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@hfID", SqlDbType.Int,4),
					new SqlParameter("@hfPcID", SqlDbType.NVarChar,50),
					new SqlParameter("@hfNum", SqlDbType.SmallInt,2),
					new SqlParameter("@hfWeight", SqlDbType.Decimal,9),
					new SqlParameter("@hfPrice", SqlDbType.Decimal,9),
					new SqlParameter("@hfFee", SqlDbType.Decimal,9),
					new SqlParameter("@hfFeeNow", SqlDbType.Decimal,9),
					new SqlParameter("@hfRemark", SqlDbType.NVarChar,100)};
            parameters[0].Value = model.hfID;
            parameters[1].Value = model.hfPcID;
            parameters[2].Value = model.hfNum;
            parameters[3].Value = model.hfWeight;
            parameters[4].Value = model.hfPrice;
            parameters[5].Value = model.hfFee;
            parameters[6].Value = model.hfFeeNow;
            parameters[7].Value = model.hfRemark;

            return DbHelperSQL.GetIsRunOK_TranSql("UP_Head_FacTake_Update", parameters);
        }

        /// <summary>删除一条数据
        ///      <remarks>2010-12-30 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="hfID">编号</param>
        /// <returns>返回是否删除成功</returns>
        public bool Delete(string hfID)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@hfID", SqlDbType.Int)};
            parameters[0].Value = hfID;

            return DbHelperSQL.GetIsRunOK("UP_Head_FacTake_Delete", parameters);
        }

        /// <summary>获取原材料消耗列表
        ///      <remarks>2010-12-31 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="fiID">工厂编号</param>
        /// <param name="fiTime">时间</param>
        /// <returns>返回是否删除成功</returns>
        public SqlDataReader CreateList(string fiID, string fiTime)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@fiID", SqlDbType.NVarChar,20),
                    new SqlParameter("@fiTime", SqlDbType.DateTime)};
            parameters[0].Value = fiID;
            parameters[1].Value = fiTime;

            return DbHelperSQL.RunProcedure("UP_Head_FacTake_CreateList", parameters);
        }

        /// <summary>批量删除记录
        ///      <remarks>2010-12-30 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="hfIDlist">编号</param>
        /// <returns>返回删除的记录条数</returns>
        public int DeleteList(string hfIDlist)
        {
            int i = 0;
            try
            {
                string[] hfID = hfIDlist.Split(',');
                foreach (string str in hfID)
                {
                    if (Delete(str))
                    {
                        i++;
                    }
                }
                return i;
            }
            catch
            {
                return i;
            }
        }

        /// <summary>得到一个对象实体
        ///      <remarks>2010-12-30 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="hfID">编号</param>
        /// <returns>返回Model</returns>
        public IMIS_ERP.Model.Head_FacTake GetModel(int hfID)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@hfID", SqlDbType.Int,4)};
            parameters[0].Value = hfID;

            IMIS_ERP.Model.Head_FacTake model = new IMIS_ERP.Model.Head_FacTake();
            DataSet ds = DbHelperSQL.RunProcedure("UP_Head_FacTake_GetModel", parameters, "ds");
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["hfID"].ToString() != "")
                {
                    model.hfID = int.Parse(ds.Tables[0].Rows[0]["hfID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["hfTime"].ToString() != "")
                {
                    model.hfTime = DateTime.Parse(ds.Tables[0].Rows[0]["hfTime"].ToString());
                }
                model.hfFiID = ds.Tables[0].Rows[0]["hfFiID"].ToString();
                model.hfType = ds.Tables[0].Rows[0]["hfType"].ToString();
                model.hfPcID = ds.Tables[0].Rows[0]["hfPcID"].ToString();
                if (ds.Tables[0].Rows[0]["hfNum"].ToString() != "")
                {
                    model.hfNum = int.Parse(ds.Tables[0].Rows[0]["hfNum"].ToString());
                }
                if (ds.Tables[0].Rows[0]["hfWeight"].ToString() != "")
                {
                    model.hfWeight = decimal.Parse(ds.Tables[0].Rows[0]["hfWeight"].ToString());
                }
                if (ds.Tables[0].Rows[0]["hfPrice"].ToString() != "")
                {
                    model.hfPrice = decimal.Parse(ds.Tables[0].Rows[0]["hfPrice"].ToString());
                }
                if (ds.Tables[0].Rows[0]["hfFee"].ToString() != "")
                {
                    model.hfFee = decimal.Parse(ds.Tables[0].Rows[0]["hfFee"].ToString());
                }
                if (ds.Tables[0].Rows[0]["hfFeeNow"].ToString() != "")
                {
                    model.hfFeeNow = decimal.Parse(ds.Tables[0].Rows[0]["hfFeeNow"].ToString());
                }
                model.hfRemark = ds.Tables[0].Rows[0]["hfRemark"].ToString();
                model.hfHuID = ds.Tables[0].Rows[0]["hfHuID"].ToString();
                model.hfVoucher = ds.Tables[0].Rows[0]["hfVoucher"].ToString();
                if (ds.Tables[0].Rows[0]["hfIsPay"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["hfIsPay"].ToString() == "1") || (ds.Tables[0].Rows[0]["hfIsPay"].ToString().ToLower() == "true"))
                    {
                        model.hfIsPay = true;
                    }
                    else
                    {
                        model.hfIsPay = false;
                    }
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>获得加工中心某段时间的报表
        ///     <remarks>2011-05-10 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="fiProvince">省</param>
        /// <param name="fiCity">市</param>
        /// <param name="oiTime1">开始时间</param>
        /// <param name="oiTime2">结束时间</param>
        /// <returns>返回DataSet</returns>
        public DataSet GetRpt(string fiProvince, string fiCity, string oiTime1, string oiTime2)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@fiProvince", SqlDbType.NVarChar,20),
                    new SqlParameter("@fiCity", SqlDbType.NVarChar,50),
                    new SqlParameter("@oiTime1", SqlDbType.DateTime),
                    new SqlParameter("@oiTime2", SqlDbType.DateTime)};
            parameters[0].Value = fiProvince;
            parameters[1].Value = fiCity;
            parameters[2].Value = oiTime1;
            parameters[3].Value = oiTime2;

            return DbHelperSQL.RunProcedure("UP_Head_FacTake_GetRpt", parameters, "a");
        }

        /// <summary>获得数据列表
        ///     <remarks>2010-12-30 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="strWhere">查询条件</param>
        /// <returns>返回DataSet</returns>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select hfID,hfTime,hfFiID,hfType,hfPcID,hfWeight,hfPrice,hfFee,hfHuID,hfVoucher,hfIsPay ");
            strSql.Append(" FROM Head_FacTake ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>获得前几行数据
        ///     <remarks>2010-12-30 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="Top">行数</param>
        /// <param name="strWhere">条件</param>
        /// <param name="filedOrder">排序</param>
        /// <returns>返回DataSet</returns>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" hfID,hfTime,hfFiID,hfType,hfPcID,hfWeight,hfPrice,hfFee,hfHuID,hfVoucher,hfIsPay ");
            strSql.Append(" FROM Head_FacTake ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>获得报表数据
        ///     <remarks>2011-08-10 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="time1">开始时间</param>
        /// <param name="time2">结束时间</param>
        /// <returns>返回DataSet</returns>
        public DataSet GetList_Report(string time1, string time2)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select hfID,hfTime,hfFiID,hfType,hfPcID,hfWeight,hfPrice,hfFee,hfHuID,hfVoucher,hfIsPay FROM Head_FacTake where hfTime>='");
            strSql.Append(time1);
            strSql.Append("' and hfTime<='");
            strSql.Append(time2);
            strSql.Append("'");
            return DbHelperSQL.Query(strSql.ToString());
        }

        #endregion  Method
    }
}

